import { queryForList, deleteData, getById, createOrUpdate } from '@/api/system/entityApi'

const state = {
}

const mutations = {
}

const actions = {
  queryForList({ commit }, entity) {
    const { title, tableName, pager } = entity
    return new Promise((resolve, reject) => {
      queryForList({ title, tableName, pager }).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  createOrUpdate({ commit }, entity) {
    const { id, title, tableName, saveToEs, module, description } = entity
    return new Promise((resolve, reject) => {
      createOrUpdate({ id, title, tableName, saveToEs, module, description }).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  deleteData({ commit }, dataId) {
    return new Promise((resolve, reject) => {
      deleteData(dataId).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  getById({ commit }, dataId) {
    return new Promise((resolve, reject) => {
      getById(dataId).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

